package com.jspgou.cms.entity;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;

import com.jspgou.cms.entity.base.BasePayment;

public class Payment extends BasePayment {
	private static final long serialVersionUID = 1L;
	/**
	 * 线下支付
	 */
	public static final String OFFLINE = "offline";

	/**
	 * 货到付款
	 */
	public static final String COD = "cash_on_delivery";
	/**
	 * 支付宝
	 */
	public static final String ALIPAY = "alipay";

	/**
	 * 支付宝
	 */
	public static final String ALIPAYPARTNER = "alipayPartner";
	/**
	 * 微信扫码支付
	 */
	public static final String WECHATSCANCODEPAY="weChatScancodePay";
	/**
	 * 支付种类
	 */
	public static final String[] PAYMENT_TYPE = { OFFLINE, COD,ALIPAY, ALIPAYPARTNER,WECHATSCANCODEPAY};

	public Map<String, String> getCfg() {
		Map<String, String> map = new HashMap<String, String>();
		String config = getConfig();
		if (!StringUtils.isBlank(config)) {
			try {
				JSONObject j = new JSONObject(config);
				for (String name : JSONObject.getNames(j)) {
					map.put(name, j.getString(name));
				}
			} catch (JSONException e) {
				throw new RuntimeException(e);
			}
		}
		return map;
	}

	public void setCfg(Map<String, String> map) {
		if (map == null || map.size() <= 0) {
			setConfig(null);
		} else {
			JSONObject jo = new JSONObject(map);
			setConfig(jo.toString());
		}
	}

	/* [CONSTRUCTOR MARKER BEGIN] */
	public Payment() {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Payment(java.lang.Long id) {
		super(id);
	}

	/**
	 * Constructor for required fields
	 */
	public Payment(java.lang.Long id, com.jspgou.core.entity.Website website,
			java.lang.String name, java.lang.String code,
			java.lang.Integer priority, java.lang.Boolean disabled) {

		super(id, website, name, code, priority, disabled);
	}

	/* [CONSTRUCTOR MARKER END] */

}